import { BaseView } from "../../base/BaseView";
import { layerMgr } from "../../com/LayerMgr";
import { loginMod } from "./LoginMod";
import { MsgVo } from "../../cfg/Msg";
import { popupMgr } from "../../com/PopupMgr";
import { ScrollList } from "../../comp/ScrollList";
import { Views } from "../../cfg/XlsxDef";
import { EditBox, _decorator, } from 'cc';
const { ccclass, property } = _decorator;

@ccclass("LoginView")
export class LoginView extends BaseView {

    @property(ScrollList)
    svrList: ScrollList<MsgVo.login.Svr>;
    @property(EditBox)
    editUser: EditBox;

    protected onOpen(): void {
        layerMgr.close(Views.LoadingView);
        let msg: MsgVo.login.toc_getSvrList = this.args[0];
        this.svrList.list = msg.svrList;
        this.svrList.setSelectedIdx(0);
        this.editUser.string = localStorage.getItem("LoginView-editUser") || "";
    }

    protected offListeners(): void {

    }

    protected onClose(): void {

    }

    onClickEnter() {
        if (!this.svrList.selection) return popupMgr.showFloatText("请先选择服务器");
        if (!this.editUser.string) return popupMgr.showFloatText("请输入你的账号");
        localStorage.setItem("LoginView-editUser", this.editUser.string);
        loginMod.tosLogin(this.svrList.selection.sid, this.editUser.string);
    }
}